﻿Imports System.Web
Imports Mysoft.Map.Data
Imports Mysoft.Map.Application
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Xml
Imports Mysoft.Slxt.Business
Imports System.IO
Imports Mysoft.PubProject.Business

Partial Public Class SetSubMedia_XMLHTTP
    Inherits System.Web.UI.Page



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strYwType As String                 '业务类型
        Dim strOnlyFlag, strTxt As String       'resquest值
        Dim strReturn As String = ""            '返回值

        strYwType = Request.QueryString("ywtype")           '业务标识
        strOnlyFlag = Request.QueryString("ywonlyflag")     '唯一键值
        strTxt = Request.QueryString("ywtxt")               '其它参数值
        strYwType = Request.QueryString("ywtype")

        '接收post的长文本值
        Dim strLongText As String = ""                      'POST文本
        If Request.InputStream.Length > 0 Then
            Dim b(Request.InputStream.Length - 1) As Byte
            Request.InputStream.Read(b, 0, Request.InputStream.Length)
            strLongText = System.Text.Encoding.UTF8.GetString(b)
        End If


        Select Case strYwType.ToUpper
            Case "SubMeidaNameIsExist".ToUpper                                '效验：判断媒体子类编码在当前公司内不能重复
                strReturn = SubMeidaNameIsExist()
                Exit Select
            Case "SubMeidaCodeIsExist".ToUpper                                '效验：判断媒体子类名称在当前公司内不能重复
                strReturn = SubMeidaCodeIsExist()
                Exit Select
            Case "DelSubMeida".ToUpper                                        '删除媒体子类
                strReturn = DelSubMeida(strLongText)
                Exit Select
            Case "ValidOperate".ToUpper                                       '媒体子类有效无效操作
                strReturn = ValidOperate(strLongText)
                Exit Select
        End Select

        MyBase.Response.ContentType = "text/HTML"
        MyBase.Response.Clear()
        MyBase.Response.Write(strReturn)      ' 返回操作成功信息
        MyBase.Response.End()
    End Sub

#Region "业务处理代码"
    '效验：媒体子类名称是否有重复
    Private Function SubMeidaNameIsExist() As String
        Dim BUGUID As String = Session("BUGUID")
        Dim strSubMediaName As String = MysRequest.QueryString("SubMediaName")
        Dim strSubMediaGUID As String = MysRequest.QueryString("oid")
        Dim strSQL As String = ""
        Dim intCount As Integer
        strSQL = String.Format("SELECT COUNT(1) FROM s_SubMedia WHERE SubMediaName ='{0}'  AND BUGUID='{1}'", strSubMediaName, BUGUID)
        If strSubMediaGUID <> String.Empty Then
            strSQL &= " and SubMediaGUID<>'" + strSubMediaGUID + "'"
        End If
        Try
            intCount = MyDB.GetDataItemInt(strSQL)
            If intCount > 0 Then
                Return "NO"
            Else
                Return "OK"
            End If
        Catch ex As Exception
            Return "操作失败.请与管理员联系！"
        End Try
    End Function

    '效验：媒体子类编码是否有重复
    Private Function SubMeidaCodeIsExist() As String
        Dim BUGUID As String = Session("BUGUID")
        Dim strSubMediaCode As String = MysRequest.QueryString("SubMediaCode")
        Dim strSubMediaGUID As String = MysRequest.QueryString("oid")
        Dim strSQL As String = ""
        Dim intCount As Integer
        strSQL = String.Format("SELECT COUNT(1) FROM s_SubMedia WHERE SubMediaCode ='{0}'  AND BUGUID='{1}'", strSubMediaCode, BUGUID)
        If strSubMediaGUID <> String.Empty Then
            strSQL &= " and SubMediaGUID<>'" + strSubMediaGUID + "'"
        End If
        Try
            intCount = MyDB.GetDataItemInt(strSQL)
            If intCount > 0 Then
                Return "NO"
            Else
                Return "OK"
            End If
        Catch ex As Exception
            Return "操作失败.请与管理员联系！"
        End Try
    End Function

    '删除媒体子类
    Private Function DelSubMeida(ByVal strGUID As String) As String
        Try
            Dim strSubMediaGUID As String = strGUID.Replace(",", "','")
            Dim strSQL As String = ""

            If strSubMediaGUID <> String.Empty Then
                strSQL = String.Format("DELETE s_SubMedia WHERE SubMediaGUID IN ('{0}')", strSubMediaGUID)
            End If

            If MyDB.ExecSQL(strSQL) > -1 Then
                Return "success"
            Else
                Return "操作失败.请与管理员联系!"
            End If
        Catch ex As Exception
            Return "操作失败.请与管理员联系!"
        End Try
    End Function
    '有效无效操作
    Public Function ValidOperate(ByVal strGUID As String) As String
        Try
            Dim strSubMediaGUID As String = strGUID.Replace(",", "','")
            Dim strState As String = MysRequest.QueryString("valid")
            Dim strSQL As String = ""

            strSQL = String.Format("UPDATE s_SubMedia SET State='{0}' WHERE SubMediaGUID IN ('{1}')", strState, strSubMediaGUID)
            If MyDB.ExecSQL(strSQL) >= 0 Then
                Return "success"
            Else
                Return "操作失败.请与管理员联系!"
            End If
        Catch ex As Exception
            Return "操作失败.请与管理员联系!"
        End Try

    End Function
#End Region

End Class